﻿@{
    Layout = null;
}

<!DOCTYPE html>

<html class="x-admin-sm">
<head>
    <meta name="viewport" content="width=device-width" />
    <meta charset="UTF-8">
    <title>维修价格查询</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link href="~/Content/X-admin/css/font.css" rel="stylesheet" />
    <script src="~/Content/X-admin/lib/layui/layui.js"></script>
    <link href="~/Content/X-admin/css/xadmin.css" rel="stylesheet" />
    <script src="~/Content/X-admin/js/jquery.min.js"></script>
    <script src="~/Content/X-admin/js/xadmin.js"></script>
    <script src="~/Content/Scripts/System/systemFrame.js"></script>
    <script type="text/html" id="barDemo">
        @if (ViewData["operate"].ToString().Contains("update"))
        {
             <a title="修改" href="javascript:;" lay-event="edit"><i class="layui-icon">&#xe642;</i></a>
            <a title="删除" href="javascript:;" lay-event="del"><i class="layui-icon">&#xe640;</i></a>
        }
    </script>
</head>
<body>
    <div class="layui-fluid">
        <div class="layui-row layui-col-space15">
            <div class="layui-card-body ">
                <form class="layui-form layui-col-space5" name="qForm" id="qForm">
                    <div class="layui-inline layui-show-xs-block">
                        <input type="text" name="pCode" placeholder="岗位编码" autocomplete="off" class="layui-input" id="pCode">
                    </div>
                    <div class="layui-inline layui-show-xs-block">
                        <select id="gxCode" name="gxCode" class="gxCode">
                            <option value="">生产工序</option>
                        </select>
                    </div>
                    <div class="layui-inline layui-show-xs-block">
                        <button class="layui-btn" lay-filter="sreach" id="userSearch" type="button" onclick="loadData()"><i class="layui-icon">&#xe615;</i></button>
                    </div>

                </form>
            </div>
            <div class="layui-col-md12">
                <div class="layui-card">
           

                    @if (ViewData["operate"].ToString().Contains("update"))
                    {
                        <div class="layui-card-header">
                            <button class="layui-btn" id="addData" type="button" onclick="openWin()"><i class="layui-icon"></i>添加</button>
                        </div>
                    }

                    <div class="layui-card-body layui-table-body layui-table-main">
                        <table class="layui-hide" id="list" lay-filter="list"></table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</body>
</html>

<script type="text/javascript">
    $(function () {
        bargxInfo();
        loadData();
    })

    function loadData() {
        var conditon = JSON.stringify(FormToJson("qForm"));
        layui.use(['laydate', 'laypage', 'layer', 'table', 'carousel', 'upload', 'element', 'slider'], function () {
            var laydate = layui.laydate //日期
                , laypage = layui.laypage //分页
                , layer = layui.layer //弹层
                , table = layui.table //表格
                , carousel = layui.carousel //轮播
                , upload = layui.upload //上传
                , element = layui.element //元素操作
                , slider = layui.slider //滑块
            //给table赋值
            table.render({
                elem: '#list'
                , url: '../Basis/GetDataList?condition='+conditon+'&dataType=pstlist'//数据接口
                , title: '数据列表'
                , page: false //开启分页
                , even: true
                , limits: [20, 50, 100]
                , limit: 20 //每页默认显示的数量
                , toolbar: true //开启工具栏，此处显示默认图标，可以自定义模板，详见文档
                , defaultToolbar: ['exports']
                , cols: [[ //表头
                      { field: 'pCode', title: '编码', width: 150, fixed: 'left' }
                    , { field: 'gxName', title: '生产工序', width: 100 }
                    , { field: 'gwName', title: '岗位', width: 100 }
                    , { field: 'persons', title: '人数', width: 100 }
                    , { field: 'zhanbi', title: '占比', width: 100 }
                    , { fixed: 'right', title: '操作', width: 100, align: 'center', toolbar: '#barDemo' }
                ]]
            });

            //监听行工具事件
            table.on('tool(list)', function (obj) { //注：tool 是工具条事件名，test 是 table 原始容器的属性 lay-filter="对应的值"
                var data = obj.data //获得当前行数据
                    , layEvent = obj.event; //获得 lay-event 对应的值
                if (layEvent == 'edit') {
                    InfoOpenPage('../Basis/UpdatePosition?dataId=' + data.pCode+"&gxCode="+data.gxCode, data.pCode + "-修改", "85%", "80%");
                }
                else if (layEvent == 'del') {
                    layer.confirm('确认要删除该数据？', function (index) {

                        var info = DelData(data.id);
                        if (info.Result) {
                            obj.del();
                        } else {
                            layer.msg(info.Message);
                        }
                        layer.close(index);
                    });

                }
            });


        });
    }

    function openWin() {
        InfoOpenPage("../Basis/UpdatePosition?dataId=0", "岗位信息添加", "85%", "90%");
    }
    function DelData(dataId) {
        var info = undefined;
        $.ajax({
            url: "../Basis/DelPositionInfo",
            data: { dataId: dataId, delType: "0" },
            dataType: "json",
            type: "POST",
            async: false,
            success: function (data) {
                info = data;
            }
        });
        return info;
    }
    function bargxInfo() {
        $.ajax({
            url: "../Basis/BarTypes",
            dataType: "json",
            type: "POST",
            async: false,
            success: function (data) {
                if (data.Result) {
                    var datas = data.Data;
                    for (var i = 0; i < datas.length; i++) {
                        $(".gxCode").append("<option value=\"" + datas[i]["cCode"] + "\" >" + datas[i]["cName"] + "</option>");
                    }

                }
            }
        });
    }
</script>
